Thursday, December 12, 2024
ParaSail now on GitHub
Thanks to my colleague Olivier Henley, the full sources of ParaSail (and more) are now on GitHub:
https://github.com/parasail-lang/parasail
There is a discussion forum there for asking questions about the implementation:
https://github.com/parasail-lang/parasail/discussions
Below is the "readme" file from this GitHub repository:
This is the main source code repository for ParaSail. It contains the compiler, the interpreter, the standard library, and documentation.
Note: this README is for users rather than contributors. If you wish to contribute to the compiler, you should read the Getting Started section of the parasail-dev-guide instead. You can ask for help at Gitter.
import Clock; interface Dining_Philosophers<Num_Phils : Univ_Integer := 5; Context<>> is func Dinner_Party (Length_Of_Party : Clock::Interval_Type; Context); type Philosopher_Index is new Integer<1..Num_Phils>; type Left_Or_Right is Enum<[#is_left_fork, #is_right_fork]>; concurrent interface Fork<> is func Pick_Up_Fork(queued var F : Fork; Which_Fork : Left_Or_Right); func Put_Down_Fork(locked var F : Fork); func Create(Index : Philosopher_Index) -> Fork; end interface Fork; type Fork_Array is Array<Fork, Indexed_By => Philosopher_Index>; end interface Dining_Philosophers; class Dining_Philosophers<Num_Phils : Univ_Integer := 5; Context<>> is exports func Dinner_Party(Length_Of_Party : Clock::Interval_Type; Context) is Delay(Context.Clock.Wall_Clock, Length_Of_Party); Display(Context.IO.Standard_Output, "Dinner Party is over\n"); return; || var Forks : Fork_Array := [for I in 1..Num_Phils => Create(I)]; for Phil in Philosopher_Index concurrent loop const Left_Fork := Phil; const Right_Fork := Phil mod Num_Phils + 1; while True loop Display(Context.IO.Standard_Output, "Philosopher " | Phil | " is thinking\n"); Delay(Clock, Next(Context.Random)); // Think then Pick_Up_Fork(Forks[Left_Fork], #is_left_fork); || Pick_Up_Fork(Forks[Right_Fork], #is_right_fork); then Display(Context.IO.Standard_Output, "Philosopher " | Phil | " is eating\n"); Delay(Clock, Next(Context.Random)); // Eat then Put_Down_Fork(Forks[Left_Fork]); || Put_Down_Fork(Forks[Right_Fork]); end loop; end loop; end func Dinner_Party; concurrent class Fork<> is var Is_Available : Boolean; exports func Create(Index : Philosopher_Index) -> Fork is return (Is_Available => True); end func Create; func Pick_Up_Fork (queued var F : Fork; Which_Fork : Left_Or_Right) is queued until F.Is_Available then F.Is_Available := False; end func Pick_Up_Fork; func Put_Down_Fork(locked var F : Fork) is F.Is_Available := True; end func Put_Down_Fork; end class Fork; end class Dining_Philosophers;
- Read "ParaSail: Less is More with Multicore".
- To perfect your understanding read "ParaSail: A Pointer-Free Pervasively-Parallel Language for Irregular Computations".
- To gain reference knowledge read "ParaSail: Reference Manual".
- To follow along the original multi-year design process of ParaSail, read the blog "Designing ParaSail, a new programming language".
The ParaSail community congregates in a few places:
- Stack Overflow - Direct questions about using the language.
- Gitter - General discussion and broader questions.
If you are interested in contributing to the ParaSail project, please take a look at the Getting Started section of the parasail-dev-guide.
ParaSail is primarily distributed under the terms of the ParaSail Copyright, the ParaSail Copyright 2 and the ParaSail Copyright Lib.
See ParaSail Copyright, ParaSail Copyright 2, and ParaSail Copyright Lib for details.
Friday, July 10, 2020
A new blog on the Design and Engineering of Programming Languages
Thursday, October 31, 2019
Release 8.4 of ParaSail Interpreter, Compiler, and Debugger
Sunday, February 10, 2019
ParaSail Published in Programming Journal Vol. 3, Issue 3
http://programming-journal.org/2019/3/7/
and from there you can click through to the full PDF (the
In fact, the
https://2019.programming-conference.org/
So come on down to Genoa in April if you are in the neighborhood. The presentation on ParaSail will be on Thursday, April 4th.
String interpolation comes to ParaSail 8.0
interface PSL::Core::Univ_String<> is
...
op "|"(Left, Right : optional Univ_String) -> Univ_String
is import(#concat_string)
op "|"(Left : optional Univ_String;
Right : optional Right_Type is Imageable<>)
-> Univ_String
op "|"(Left : optional Left_Type is Imageable<>;
Right : optional Univ_String)
-> Univ_String
...
end interface PSL::Core::Univ_String
The first "|" provides the builtin string concatenation. The other two are generic functions defined in terms of this builtin concatenation, as follows:
class PSL::Core::Univ_String is
...
exports
...
op "|"(Left : optional Univ_String;
Right : optional Right_Type is Imageable<>)
-> Univ_String is
if Right is null then
return Left | "null"
else
return Left | Right_Type::To_String(Right)
end if
end op "|"
op "|"(Left : optional Left_Type is Imageable<>;
Right : optional Univ_String)
-> Univ_String is
if Left is null then
return "null" | Right
else
return Left_Type::To_String(Left) | Right
end if
end op "|"
...
end class PSL::Core::Univ_String
---
What the above means is that when you write:
"X = " | X
this will be allowed so long as "X" is of a type that satisfies the "Imageable" interface, which is defined as follows:
abstract interface PSL::Core::Imageable<> is
func To_String(Val : Imageable) -> Univ_String<>
optional func From_String(Str : Univ_String<>) -> optional Imageable
// NOTE: We include Hashable<> operations here
// so that Set
// Clearly if something is Imageable it is possible
// to implement "=?" and Hash using the string image,
// so we might as well requires these operations too.
op "=?"(Left, Right : Imageable) -> Ordering
func Hash(Val : Imageable) -> Univ_Integer
end interface PSL::Core::Imageable
---
The availability of the To_String operation is the critical aspect of Imageable that we use for the "|" operator. We expand "X = " | X into:
"X = " | To_String(X)
and so long as X's type has an appropriate To_String operation, everything works smoothly. What this means is that you almost never have to write a call on To_String explicitly, by just alternating between string literals and expressions that you want to print, you can write things like:
Println ("X = " | X | ", Y = " | Y | ", X + Y = " | X + Y | "!");
which is clearly less verbose than:
Println ("X = " | To_String(X) | ", Y = " | To_String(Y) | ", X + Y = " | To_String(X + Y) | "!");
Nevertheless, even in the more concise version, all of those alternating quotes and '|' characters can become hard for the human to parse, and it is easy to forget one of the needed characters. So what to do?
STRING INTERPOLATION
A (growing) number of languages support the ability to "interpolate" the values of variables, or in some cases expressions, directly into string literals. This has been true for simple variables since the beginning for languages like the Unix/GNU-Linux shell:
echo "X = $X, Y = $Y"
Interpolating the value of more complex expressions is sometimes supported, but generally requires some additional syntax.
Very early on, most variants of the LISP language supported the ability to construct list structures explicitly, using the "quote" operation, along with an ability to insert a LISP expression (aka "S-expression") in the middle that was to be evaluated and substituted into the list structure that was being defined. E.g.:
(define celebrate (lambda (name) (quote (Happy Birthday to (unquote (capitalize name))))))
and then "(celebrate (quote sam))" evaluates to "(Happy Birthday to Sam)".
As a short-hand, in most versions of LISP:
(quote (a b c))
becomes something like:
'(a b c)
and (unquote blah) becomes, depending on the version of LISP, something like:
`blah
or
,blah
So the above definition of "celebrate" using these short-hands becomes:
(define celebrate (lambda (name) '(Happy Birthday to ,(capitalize name))))
with (celebrate 'sam) becoming (Happy Birthday to Sam)
PARASAIL STRING INTERPOLATION
Ok, so how does this relate to ParaSail? So the explicit use of the "|" operator and having to end a string literal, insert the expressions between | ... |, and then restart the string literal gets old. Given that there aren't an infinite number of ParaSail programs already in existence, and the fact that the back-quote character is almost never used, we decided to hi-jack the meaning of back-quote when it appears in the middle of a string literal to reduce all the back and forth needed when using an explicit "|" operator. Hence, we now allow:
Println("X = `(X), Y = `(Y), X + Y = `(X + Y)!");
In other words, you can "interpolate" the value of an arbitrary (Imageable) expression into the middle of a ParaSail string literal by using `(
The lexical analyzer then expects a left parenthesis to be the next character, and counts matching parentheses, and when it reaches the matching right parenthesis, it emits the two characters: | "
The net effect is that "X = `(X), ..." becomes:
"X = " | (X) | ", ..."
Note that the parentheses are preserved, to avoid issues with precedence between the "|" operator and operators that might occur within the parentheses. Also note that the parenthesized expression can be separated from the back-quote by white space, and the expression can also span multiple lines if necessary. The lexer is smart enough to use a stack, so that the parenthesized expression can also have nested string literals, that themselves use interpolation.
If you have looked at past source releases of the ParaSail LLVM-based compiler (which is itself written in Parasail -- see lib/compiler.psl), you might want to take a look at the version of lib/compiler.psl in the 8.0 release. It makes heavy use of string interpolation, and hopefully is easier to read because of that.
Saturday, February 9, 2019
Release 8.0 of ParaSail Interpreter, Compiler, and Debugger
Enjoy!
Wednesday, November 2, 2016
Release 7.0 of ParaSail interpreter, VM, and compiler -- sources plus linux/mac binaries
This release is the first in a while to include binaries, though it only includes binaries for Mac and Linux (Windows is being difficult ... ;-{). The release is at:
http://bit.ly/psl7rel
If you have any problems, please report them on the ParaSail google group:
https://groups.google.com/forum/#!forum/parasail-programming-language